package com.hxy.health.platform.service.impl;

import com.hxy.health.platform.dao.OrderMapper;
import com.hxy.health.platform.pojo.Cart;
import com.hxy.health.platform.pojo.Order;
import com.hxy.health.platform.service.OrderService;
import com.hxy.health.platform.utils.OrderNumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    /**
     * 添加商品
     * @param cartList
     * @return
     */
    @Override
    public int addOrder(List<Cart> cartList, Order order) {
        long orderNum = OrderNumUtil.generateOrderNum();
        for (Cart cart : cartList) {
            Order newOrder = new Order();
            newOrder.setOrderNum(String.valueOf(orderNum));
            newOrder.setAddressDetail(order.getAddressDetail());
            newOrder.setCode(order.getCode());
            newOrder.setCompanyName(order.getCompanyName());
            newOrder.setEmail(cart.getEmail());
            newOrder.setImgUrl(cart.getProductImg());
            newOrder.setOrderStatus(1);
            newOrder.setPayType(order.getPayType());
            newOrder.setPayment(order.getPayment());
            newOrder.setPhone(order.getPhone());
            newOrder.setSinglePrice(cart.getProductPrice());
            newOrder.setPhone(order.getPhone());
            newOrder.setPayTime(new Date());
            newOrder.setProductId(cart.getProductId());
            newOrder.setProductName(order.getProductName());
            newOrder.setTotalPrice(cart.getProductTotalPrice());
            newOrder.setQu(order.getQu());
            newOrder.setQuantity(cart.getQuantity());
            newOrder.setReciver(order.getReciver());
            newOrder.setSheng(order.getSheng());
            newOrder.setShi(order.getShi());
            orderMapper.insertSelective(newOrder);
        }
        return 1;
    }
}
